script_enemy_main{

let shot1=0;
let bullet1=[];
let timer1=[];
let angle1=[];
let radius1=[];
let direction1=[];
let bounce1=[];
let xpos1=[];
let ypos1=[];

let misangle=0;
let size=20;
let shoot=0;

let character="Midori";
let cutin=character;
let dispelled=0;
let spellcards=1;
let spellcardnumber=73;
let damagerate=10;
let outfit=1;
outfit=(128*outfit)-128;
let usespell=0;
let bgfade=0;
let frame=0;
let time=0;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;

let SEmagics5=("\script\SoundEffects\magics5.wav");
let SEshotb5=("\script\SoundEffects\shotb5.wav");

let BG1=("\script\Images\BackgroundLayers\Midori1.png");
let GRboss=("\script\Images\CharacterSprites\Midori.png");

#include_function "script/Functions/SetSpellcardCommonData.txt";
#include_function "script/Functions/SpellcardNameLoad.txt";
#include_function "script/Functions/HealthBarLoad.txt";
#include_function "script/Functions/CutInLoad.txt";

@Initialize{
	LoadUserShotData("script\shots\ShotsMidori1.txt");

	LoadSE("\script\SoundEffects\magics5.wav");
	LoadSE("\script\SoundEffects\shotb5.wav");

	LoadGraphic("\script\Images\BackgroundLayers\Midori1.png");
	LoadGraphic("\script\Images\CharacterSprites\Midori.png");

	SetScore(2500000);
	SetLife(1000);
	SetTimer(80);
	SetInvincibility(120);
	SetDamageRate(10,10);
	SetEnemyMarker(true);
	MagicCircle(true);
	#include_function "script/Functions/Focus.txt";
	Focus(character);
	SetEffectForZeroLife(60,100,1);
	SetMovePosition02(cx,miny+100,50);

	SetDurableSpellCard;
}
	
@MainLoop{

SetCollisionA(GetX,GetY,16);
SetCollisionB(GetX,GetY,16);
SetShotAutoDeleteClip(32,32,32,32);

Weakness(character);
#include_function "script/Functions/Weakness.txt";
if(GetCommonData("BombOn")==0){ damagerate=10; }
if(GetCommonData("BombOn")==1){ damagerate=0; }
SetDamageRate(damagerate*weaken,damagerate*weaken);

let difficulty="";
if(GetCommonDataDefault("Difficulty",2)==1){ difficulty="Easy"; }
if(GetCommonDataDefault("Difficulty",2)==2){ difficulty="Normal"; }
if(GetCommonDataDefault("Difficulty",2)==3){ difficulty="Hard"; }
if(GetCommonDataDefault("Difficulty",2)==4){ difficulty="Lunatic"; }

SpellcardName("Philophobia [Fear Of Falling In Love]",spellcardnumber); 
HealthBar();
Portrait(cutin,1);


if((time+100)%150==0 && time>=60){
	if(GetPlayerX>minx+50 && GetPlayerX<maxx-50){
	SetMovePosition01(GetPlayerX+rand(-30,30),rand(miny+60,miny+120),1.5);
	}
	if(GetPlayerX<=minx+50){
	SetMovePosition01(GetPlayerX+rand(15,30),rand(miny+60,miny+120),1.5);
	}
	if(GetPlayerX>=maxx-50){
	SetMovePosition01(GetPlayerX-rand(15,30),rand(miny+60,miny+120),1.5);
	}
}


if(time%150==0 && time>=60){
let dir=0;
if(time%300==0){ dir=0.5; }
if(time%300!=0){ dir=-0.5; }
let angle=rand(0,360);
	loop(size){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX,GetY-10);
	Obj_SetAngle(shot1,angle);
	Obj_SetSpeed(shot1,0);
	Obj_SetAutoDelete(shot1,false);
	if(dir<0){ ObjShot_SetGraphic(shot1,25); }
	if(dir>0){ ObjShot_SetGraphic(shot1,34); }
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1]; timer1[length(bullet1)-1]=0;
	angle1=angle1~[shot1]; angle1[length(bullet1)-1]=angle;
	radius1=radius1~[shot1]; radius1[length(bullet1)-1]=0;
	direction1=direction1~[shot1]; direction1[length(bullet1)-1]=dir;
	bounce1=bounce1~[shot1]; bounce1[length(bullet1)-1]=0;
	xpos1=xpos1~[shot1]; xpos1[length(bullet1)-1]=GetX;
	ypos1=ypos1~[shot1]; ypos1[length(bullet1)-1]=GetY-10;
	angle+=360/size;
	}
if(size<35){ size+=1; }
if(misangle<2){ misangle+=0.1; }
usespell=-40;
PlaySE(SEshotb5);
}

let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){
	bullet1=erase(bullet1,i); timer1=erase(timer1,i); angle1=erase(angle1,i); radius1=erase(radius1,i);
	direction1=erase(direction1,i); bounce1=erase(bounce1,i); xpos1=erase(xpos1,i); ypos1=erase(ypos1,i);
	i--;
	}
	else{
	let obj=bullet1[i];
	Obj_SetPosition(bullet1[i],xpos1[i]+radius1[i]*cos(angle1[i]),ypos1[i]+radius1[i]*sin(angle1[i]));
	if(direction1[i]<0){ Obj_SetAngle(bullet1[i],angle1[i]-90); }
	if(direction1[i]>0){ Obj_SetAngle(bullet1[i],angle1[i]+90); }
		if(Obj_GetX(obj)<=minx-10){ bounce1[i]=bounce1[i]+1; }
		if(Obj_GetX(obj)>=maxx+10){ bounce1[i]=bounce1[i]+1; }
		if(Obj_GetY(obj)<=miny-10){ bounce1[i]=bounce1[i]+1; }
		if(Obj_GetY(obj)>=maxy+10){ bounce1[i]=bounce1[i]+1; }
		if(bounce1[i]==1){
		let angle=0;
			loop(4){
			let speed=2;
				loop(5){
				if(direction1[i]<0){ CreateShot01(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),speed,angle+rand(-misangle,misangle),37,0); }
				if(direction1[i]>0){ CreateShot01(Obj_GetX(bullet1[i]),Obj_GetY(bullet1[i]),speed,angle+rand(-misangle,misangle),46,0); }
				speed-=0.2;
				}
			angle+=360/4;
			}
		bounce1[i]=bounce1[i]+1;
		if(shoot==0){ PlaySE(SEmagics5); shoot=5; }
		}
		if(radius1[i]>500){ Obj_Delete(bullet1[i]); }
	angle1[i]=angle1[i]+direction1[i]*(1-(timer1[i]/400));
	radius1[i]=radius1[i]+1.5;
	timer1[i]=timer1[i]+1;
	}
i++;
}

if(shoot>0){ shoot-=1; }


time++; frame++;
if(usespell>0){ usespell--; } if(usespell<0){ usespell++; }
SetCommonData("Boss1X",GetX); SetCommonData("Boss1Y",GetY);

#include_function "script/Functions/SpellcardName.txt";
#include_function "script/Functions/HealthBar.txt";
#include_function "script/Functions/CutIn.txt";

if(GetLife==0 && dispelled==0){ CreateEnemyFromFile("script\Functions\dispel.txt",GetX,GetY,0,0,character); dispelled=1; }
}

@BackGround{
	if(bgfade<125){ bgfade+=5; }

	SetGraphicRect(0,0,600,600);
	SetGraphicScale(2,2);
	SetTexture(BG1);
	SetRenderState(ALPHA);
	
	SetAlpha(bgfade*2);
	SetColor(127+127*cos(time),127+127*cos(time+120),127+127*cos(time+240));
	SetGraphicAngle(0,0,-time);
	DrawGraphic(cx-150,cy);
	
	SetColor(127-127*cos(time),127-127*cos(time+120),127-127*cos(time+240));
	SetAlpha(bgfade);
	SetGraphicAngle(0,0,time);
	DrawGraphic(cx+150,cy);
}

@DrawLoop{
	SetGraphicScale(1,1);
	SetTexture(GRboss);
	SetGraphicAngle(0,0,0);
	SetColor(255,255,255);
	SetRenderState(ALPHA);

	if(usespell>=1){ SetGraphicRect(384,outfit,512,outfit+128); }
	if(usespell<=-1){ SetGraphicRect(512,outfit,640,outfit+128); }
	if(usespell==0){
		if(GetSpeedX<=0.5 && GetSpeedX>=-0.5){ SetGraphicRect(0,outfit,128,outfit+128); }
		else if(GetSpeedX<-0.5){ SetGraphicRect(128,outfit,256,outfit+128); }
		else if(GetSpeedX>0.5){ SetGraphicRect(256,outfit,384,outfit+128); }
	}
	DrawGraphic(GetX,GetY);
}

@Finalize{
	if(GotSpellCardBonus){ SetCommonData("LastTrumpCard",6); }
	NewPointData(spellcardnumber,7);
	#include_function "script/Functions/Main Menu/SpellcardDataAndPoints.txt";
}

}